package com.xiong.m3u8;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class Test {


    public static void main(String[] args) throws Exception {
      //  FfmpegUtil.mp4ToM3u8("D:\\video\\魏晨 - 尘埃.mp4","D:\\video\\m3u8");
      //  FfmpegUtil.getVideoPic(new File("D:\\video\\魏晨 - 尘埃.mp4"),"D:\\video\\123.jpeg");
      //  double time=FfmpegUtil.getVideoTime(new File("D:\\video\\魏晨 - 尘埃.mp4"));
       // FfmpegUtil.compressVideo(new File("D:\\video\\魏晨 - 尘埃.mp4"),true);
     //   FfmpegUtil.addWaterVideo("D:\\video\\魏晨 - 尘埃.mp4","X.I.O","D:\\video\\魏晨 - 尘埃222222.mp4");
     // FfmpegUtil.addWaterImage("D:\\video\\123.jpeg","X.I.O","D:\\video\\1234.jpeg");
      //  System.out.println(time);
     //   FfmpegUtil.cutVideo(new File("D:\\video\\魏晨 - 尘埃.mp4"),new File("D:\\video\\魏晨 - 尘埃11111111.mp4"),100,200);
//
//        List<String> strings=new ArrayList<>();
//        strings.add("D:\\video\\BEYOND - 海阔天空.mp4");
//        strings.add("D:\\video\\G.E.M. 邓紫棋 - 光年之外.mp4");
//        strings.add("D:\\video\\半阳 - 流浪.mp4");
//        FfmpegUtil.videoMerge(strings,"D:\\video\\456.mp4");
          scanPath("D:\\video\\test");
    }

    public static void scanPath(String path) throws Exception {
        File file=new File(path);
        File[] files=file.listFiles();
        for (int i = 0; i < files.length ; i++) {
            File f = files[i];
            if(f.isDirectory()){
                continue;
            }
            System.out.println(f.getName());
            Double time=FfmpegUtil.getVideoTime(f);
            String fileName=getFileNameWithoutExtension(f);
           // FfmpegUtil.getVideoPic(f,f.getParent()+File.separator+fileName+File.separator+System.currentTimeMillis()+".jpeg");
            File file1=new File(f.getParent()+File.separator+fileName);
            if(!file1.exists()){
                file1.mkdirs();
            }
            String str=FfmpegUtil.mp4ToM3u8(f.getPath(),f.getParent()+File.separator+fileName);
            System.out.println(str+" : "+time);
            boolean deleted = f.delete();
            if (!deleted) {
                f.deleteOnExit();
            }
        }

    }

    public static String getFileNameWithoutExtension(File file) {
        String fileName = file.getName();
        int index = fileName.lastIndexOf('.');
        if (index != -1) {
            fileName = fileName.substring(0, index);
        }
        return fileName;
    }


}
